package asia.redact.bracket.exampleclasses;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class PurchaseOrder extends ExampleBase  {
	
	Date orderDate;
	
	ShipTo shipTo;
	BillTo billTo;
	
	List<Item> items;

	public PurchaseOrder() {}
	
	public PurchaseOrder(Date orderDate, ShipTo shipTo, BillTo billTo) {
		super();
		this.orderDate = orderDate;
		this.shipTo = shipTo;
		this.billTo = billTo;
		this.items = new ArrayList<Item>();
	}
	
	public PurchaseOrder(Date orderDate, ShipTo shipTo, BillTo billTo, List<Item> items) {
		super();
		this.orderDate = orderDate;
		this.shipTo = shipTo;
		this.billTo = billTo;
		this.items = items;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public ShipTo getShipTo() {
		return shipTo;
	}

	public void setShipTo(ShipTo shipTo) {
		this.shipTo = shipTo;
	}

	public ShipTo getBillTo() {
		return billTo;
	}

	public List<Item> getItems() {
		return items;
	}

	public void setItems(List<Item> items) {
		this.items = items;
	}
	
	public void addItem(Item item) {
		if(items == null) items = new ArrayList<Item>();
		items.add(item);
	}

	public void setBillTo(BillTo billTo) {
		this.billTo = billTo;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((billTo == null) ? 0 : billTo.hashCode());
		result = prime * result + ((items == null) ? 0 : items.hashCode());
		result = prime * result
				+ ((orderDate == null) ? 0 : orderDate.hashCode());
		result = prime * result + ((shipTo == null) ? 0 : shipTo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		PurchaseOrder other = (PurchaseOrder) obj;
		if (billTo == null) {
			if (other.billTo != null)
				return false;
		} else if (!billTo.equals(other.billTo))
			return false;
		if (items == null) {
			if (other.items != null)
				return false;
		} else if (!items.equals(other.items))
			return false;
		if (orderDate == null) {
			if (other.orderDate != null)
				return false;
		} else if (!orderDate.equals(other.orderDate))
			return false;
		if (shipTo == null) {
			if (other.shipTo != null)
				return false;
		} else if (!shipTo.equals(other.shipTo))
			return false;
		return true;
	}

	

}
